<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }


    /**
     *  获取首页幻灯片
     */
    public function getSlider(){

        $slider =Db::name('banner')->where('status',1)->select();

        foreach ($slider as $key => $value){
            $slider[$key]['image'] = cdnurl($value['image'],true);
        }

        $this->success('获取首页幻灯片',$slider);

    }

    /**
     * 地址信息  service
     */
    public function getAddress(){

        $address = Db::name('city')->order('weigh asc')->select();
        $this->success('获取地址信息成功',$address);

    }


    /**
     *月份 获取当前日期到下月末的日期
     */

    public function getdate()
    {

        $date = [];

        for ($i=1; $i <= 20; $i++) {
            $date[] =['label'=> date('Y-m-d',strtotime("+".$i." day"))];
        }
        $time=[];

        $time[] =['label'=> '上午（7:30-11:30)'];
        $time[] =['label'=> '下午（13:00-17:00）'];
        $time[] =['label'=> '晚上（15:00-19:00）'];
        $time[] =['label'=> '全天（7:30-16:30）'];



        $this->success('获取成功',[$date,$time]);

    }


    /**
     * xieyi  获取协议
     */
    public function getXieyi()
    {

        $xieyi = Db::name('xieyi')->find();

        $this->success('获取成功',$xieyi);

    }

    /**
     * 提供的服务
     */

    public function getService(){


        $service = Db::name('service')->where('status',1)->select();


        foreach ($service as $key => $value){
            $service[$key]['image'] = cdnurl($value['image'],true);
        }

        $this->success('获取成功',$service);

    }

    /**
     * 服务详情
     */

    public function getServicebyid(){

        $id = $this->request->get('id');

        if($id){

            $service = Db::name('service')->where('id',$id)->find();

            $service['image'] = cdnurl($service['image'],true);

            $this->success('获取成功',$service);
        }

        $sid=$this->request->get('sid');

        if($sid){

            $service=Db::name('hospital_service')
                ->where(['status'=>1])
                ->where(['id'=>$sid])
                ->find();




            $service['image'] = cdnurl($service['image'],true);

            $this->success('获取成功',$service);
        }


    }



}
